package com.lijianpo.util.extension.validator.constraintvalidation;

import cn.hutool.core.lang.Validator;
import com.lijianpo.util.extension.validator.constraints.Chinese;
import org.apache.commons.lang3.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;


/**
 * 
 *验证中文
 *@author: zhangyang
 *@since: 2019年1月31日下午4:19:58
 */
public class ChineseValidator implements ConstraintValidator<Chinese, String> {
	
	@Override
	public void initialize(Chinese constraintAnnotation) {
	}

	@Override
	public boolean isValid(String value, ConstraintValidatorContext context) {
		if(StringUtils.isEmpty(value)) {
			return true;
		}
		return Validator.isChinese(value);
	}

	

}
